<template>
  <el-card shadow="never">
    <div slot="header">
      <el-button @click="handleBack">返回</el-button>
    </div>
    <el-tabs v-model="active">
      <el-tab-pane label="基本信息" name="first">
        <el-row :gutter="20">
          <el-col :span="8">
            <detail-card ref="detailCard" />
          </el-col>
          <el-col :span="16">
            <second-card ref="secondCard" />
          </el-col>
        </el-row>
      </el-tab-pane>
    </el-tabs>
  </el-card>
</template>

<script>
import DetailCard from './DetailCard'
import SecondCard from './SecondCard'
import { getInternalPlanInfo, getUserTaskDetail, getDeptTaskDetail, getAllTaskDetail } from '@/api/satisfaction'
import { getSession, setSession, removeSession } from '@/utils/util'

export default {
  components: {
    DetailCard,
    SecondCard
  },
  data() {
    return {
      active: 'first',
      row: JSON.parse(this.$route.query.row),
      type: this.$route.query.type
    }
  },
  async created() {
    if (this.row) {
      console.log('row', this.row)
      let res1 = null
      if (this.type === 'my') {
        const res = await getInternalPlanInfo({ internalPlanId: this.row.internalPlanId })
        res1 = await getUserTaskDetail({ internalTaskId: this.row.internalTaskId, targetMode: res.data.targetMode })
        // res1 = await getInternalTaskFinish({ internalTaskId: this.row.internalTaskId, targetMode: res.data.targetMode })
      }
      if (this.type === 'dept') {
        res1 = await getDeptTaskDetail({ internalTaskId: this.row.internalTaskId })
      }

      if (this.type === 'allDept') {
        res1 = await getAllTaskDetail({ internalTaskId: this.row.internalTaskId })
      }

      console.log('res1', res1.data)

      if (res1.state === '000000') {
        this.$nextTick(() => {
          this.$refs.detailCard.show(res1.data.internalTask)
          this.$refs.secondCard.show(res1.data)
        })
      }
    } else {
      this.$message.error('页面发生错误，即将返回列表页')
      setTimeout(() => {
        this.$router.go(-1)
      }, 1000)
    }
  },
  methods: {
    handleBack() {
      this.$router.go(-1)
    }
  }
}
</script>
